#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
template <class T>
class SeqTable
{
    public:
        SeqTable(int MaxSize);
        ~SeqTable();
        
        void initList();
        //declare need not the key word "inline"
        int Length();
        bool Empty();
        //Add, delete, modify, and search
        bool listInsert(int i, T x);
        bool listDelete(int i, T &x);
        bool listModify(int i, T x);
        bool getElem(int i, T &x);
        int locateElem(T x);
        //print
        void printList();
    private:
        T *data;
        int MaxSize;
        int length;
};
template <class T>
SeqTable<T>::SeqTable(int MaxSize)
{
    this->MaxSize = MaxSize;
    data = (T* )malloc(sizeof(T) * MaxSize);
    length = 0;
}

template <class T>
SeqTable<T>::~SeqTable()
{
    free(data);
}

template <class T>
void SeqTable<T>::initList()
{
    memset(data, 0, sizeof(T) * MaxSize);
}

template <class T>
inline int SeqTable<T>::Length()
{
    return length;
}
template <class T>
inline bool SeqTable<T>::Empty()
{
    return length == 0;
}
template <class T>
bool SeqTable<T>::listInsert(int i, T x)
{
    if(i < 1 || i > length+1)
    {
        return false;
    }
    else
    {
        for(int j = length; j >= i; j--)
        {
            data[j] = data[j-1];
        }
        data[i-1] = x;
        length++;
    }
    return true;
}
template <class T>
bool SeqTable<T>::listDelete(int i, T &x)
{
    if(i < 1 || i > length)
    {
        return false;
    }
    else
    {
        x = data[i-1];
        //i+1 --> i
        for(int j = i; j < length; j++)
        {
            data[j-1] = data[j];
        }
        length--;
    }
    return true;
}
template <class T>
bool SeqTable<T>::listModify(int i, T x)
{
    if (i < 1 || i > length)
    {
        return false;
    }
    else
    {
        data[i-1] = x;
    }
    return true;
}
template <class T>
bool SeqTable<T>::getElem(int i, T &x)
{
    if (i < 1 || i > length)
    {
        return false;
    }
    else
    {
        x = data[i-1];
    }
    return true;
}

template <class T>
int SeqTable<T>::locateElem(T x)
{
    for ( int i =0; i < length; i++)
    {
        if (data[i] == x)
        {
            return i+1;
        }
    }
    return 0;
}
template <class T>
void SeqTable<T>::printList()
{
    for (int i = 0; i < length; i++)
    {
        data[i].printT();
        printf("\n");
    }
}


typedef struct Point
{
    /* data */
    int x;
    int y;

    Point &operator=(const Point p)
    {
        this->x = p.x;
        this->y = p.y;
        return *this;
    }

    const bool operator==(const Point p)
    {
        return this->x == p.x && this->y == p.y;
    }

    void printT()
    {
        printf("(%d, %d)\n", x, y);
    }
}P;

void Random(SeqTable<P> &seq)
{
    srand(time(NULL));
    for (int i = 0; i < 20; i++)
    {
        P p;
        p.x = rand()%100;
        p.y = rand()%100;
        seq.listInsert(i+1, p);
    }
}
int main()
{
    SeqTable<P> seq(100);
    seq.initList();
    char c= ' ';

    printf("i: insert--position P.x P.y\n");
    printf("d: delete--position\n");
    printf("m: modify--position P.x P.y\n");
    printf("f: find--position\n");
    printf("p: print\n");
    Random(seq);
    while(c != 'q')
    {
        scanf("%c", &c);
        switch(c)
        {
            case 'i':
                P p;
                int pos;
                scanf("%d %d %d",&pos, &p.x, &p.y);
                if (!seq.listInsert(pos, p))
                    printf("error\n");
                break;
            case 'd':
                int i;
                scanf("%d", &i);
                P p1;
                if (!seq.listDelete(i, p1))
                    printf("error\n");
                else
                    p1.printT();
                break;
            case 'm':
                int j;
                scanf("%d %d %d", &j, &p.x, &p.y);
                if (!seq.listModify(j, p))
                    printf("error\n");
                break;
            case 'f':
                int k;
                scanf("%d", &k);
                P p2;
                if (!seq.getElem(k, p2))
                    printf("error\n");
                else
                    p2.printT();
                break;
            case 'p':
                seq.printList();
                break;
            case 'e':
                if(seq.Empty())
                    printf("empty\n");
                else
                    printf("not empty\n");
            case 'l':
                printf("%d\n", seq.Length());
                break;
            default:
                printf("i: insert--position P.x P.y\n");
                printf("d: delete--position\n");
                printf("m: modify--position P.x P.y\n");
                printf("f: find--position\n");
                printf("e: empty\n");
                printf("l: length\n");
                printf("p: print\n");
                break;
        }
    }
    return 0;
}